package com.lrs.java.j2se_self.lastJava;

public class TestDynacThread implements Runnable{
	T time = new T();
	public static void main(String[] args){
		TestDynacThread dy = new TestDynacThread();
		Thread t1 = new Thread(dy);
		t1.setName("t1");
		Thread t2 = new Thread(dy);
		t2.setName("t2");
		t1.start();
		t2.start();
		try{
			Thread.sleep(2000);
		}catch(InterruptedException e){
			e.printStackTrace();
		}
		System.out.println(T.num);
	}
	public void run(){
		time.add(Thread.currentThread().getName());
	}
}

class T {
	public static int num = 0;
	public synchronized void add(String s){
		//synchronized(this){
			num++;
			try{
				Thread.sleep(5000);
			}catch(InterruptedException e){
				e.printStackTrace();
			}
			System.out.println(s+"你是第"+num+"访问的对象"); 
		//}		
	}
}